package com.zsxb.crm.controller;

import com.zsxb.crm.dto.ClueReportDTO;
import com.zsxb.crm.dto.ContractPageDTO;
import com.zsxb.crm.dto.ReportDateDTO;
import com.zsxb.crm.pojo.NewUserReport;
import com.zsxb.crm.pojo.SaleReport;
import com.zsxb.crm.pojo.Series;
import com.zsxb.crm.result.PageResult;
import com.zsxb.crm.result.Result;
import com.zsxb.crm.service.ClueService;
import com.zsxb.crm.service.DeptService;
import com.zsxb.crm.service.ReportService;
import com.zsxb.crm.vo.VulnerabilityMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/report")
public class ReportController {
    @Autowired
    private ReportService reportService;
    @Autowired
    private DeptService deptService;
    @Autowired
    private ClueService clueService;

    /**
     * 首页漏斗图数据
     */
    @GetMapping("/getVulnerabilityMap/{beginCreateTime}/{endCreateTime}")
    public Result getVulnerabilityMap(ReportDateDTO dateDTO){
        VulnerabilityMap v = reportService.getVulnerabilityMap(dateDTO.getBeginCreateTime(), dateDTO.getEndCreateTime());
        return Result.success(v);
    }



    @GetMapping("/contractStatisticsList")
    public PageResult contractStatisticsList(ContractPageDTO pageDTO){
        PageResult pageResult = reportService.contractStatisticsListPageQuery(pageDTO);
        return PageResult.success(pageResult);
    }
    //查询部门
//    @GetMapping("/deptStatisticsList/2024-10-21/2024-10-28")
//    private PageResult getDepts( DeptDTO deptDTO){
//        log.info("部门统计参数为{}",deptDTO);
//        PageResult pageResult =  deptService.getDepts(deptDTO);
//        return PageResult.success(pageResult);
//    }

    /**
     * 用户数据统计
     */
    @GetMapping("/contractStatistics/{beginCreateTime}/{endCreateTime}")
    public NewUserReport contractStatistics(ReportDateDTO dateDTO){
        return reportService.contractStatistics(dateDTO.getBeginCreateTime(), dateDTO.getEndCreateTime());
    }

    /**
     * 学科数据统计
     */
    @GetMapping("/subjectStatistics/{beginCreateTime}/{endCreateTime}")
    public Series subjectStatistics(ReportDateDTO dateDTO){
        List<Map<String, Object>> subjectStatistics = reportService.subjectStatistics(dateDTO.getBeginCreateTime(), dateDTO.getEndCreateTime());
        return Series.success(subjectStatistics);
    }

    /**
     * 部门查询
     */
    @GetMapping("/deptStatisticsList/{beginCreateTime}/{endCreateTime}")
    public PageResult deptStatisticsList(ContractPageDTO pageDTO){
        PageResult pageResult = reportService.deptStatisticsList(pageDTO);
        return PageResult.success(pageResult);
    }

    /**
     * 销售统计
     */
    @GetMapping("/salesStatistics/{beginCreateTime}/{endCreateTime}")
    public SaleReport salesStatistics(ReportDateDTO dateDTO){
        return reportService.salesStatistics(dateDTO.getBeginCreateTime(), dateDTO.getEndCreateTime());
    }

    /**
     * 线索分页
     */
    @GetMapping("/cluesStatisticsList")
    public PageResult clueStatistics(ClueReportDTO clueReportDTO){
        PageResult pageResult = reportService.clueStatistics(clueReportDTO);
        return PageResult.success(pageResult);
    }

    /**
     * 线索报表
     */
    @GetMapping("/cluesStatistics/{beginCreateTime}/{endCreateTime}")
    public SaleReport cluesStatistics(ReportDateDTO dateDTO){
        return reportService.cluesStatistics(dateDTO.getBeginCreateTime(), dateDTO.getEndCreateTime());
    }

    /**
     *  渠道报表
     */
    @GetMapping("/chanelStatistics/{beginCreateTime}/{endCreateTime}")
    public Series<List<Map<String, Object>>> chanelStatistics(ReportDateDTO dateDTO){
        List<Map<String, Object>> maps = reportService.chanelStatistics(dateDTO.getBeginCreateTime(), dateDTO.getEndCreateTime());
        return Series.success(maps);
    }



}
